//
//  MeatMePhotosCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/6.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatMePhotosCell.h"

#define IconWidth 60.f
#define IconGap 5.f

@interface MeatMePhotosCell()

@property (nonatomic, strong) NSMutableArray *imageIcons;

@end

@implementation MeatMePhotosCell

#pragma mark - lifecycle methods

- (void)setupUI{
    
    [self addSubview:self.scrollView];
}

- (void)setupLayout{
    
    _scrollView.frame = CGRectMake(15, 0, KScreenWidth - 15, 60);
    _scrollView.contentSize = CGSizeMake((IconWidth +IconGap)*6 -IconGap, 60);
    
    _imageIcons = [NSMutableArray array];
    for (NSInteger k = 0; k < 6; k++) {
        UIImageView *icon = [UIImageView new];
        icon.size = CGSizeMake(IconWidth, IconWidth);
        icon.mj_y = 0;
        icon.mj_x = (IconGap + IconWidth)*k;
        icon.tag = 100 + k;
        icon.hidden = YES;
        [self addShadowAndCircleCorner:icon.layer corner:5];
        [_imageIcons addObject:icon];
        [_scrollView addSubview:icon];
    }
}


#pragma mark - setter methods

- (void)setImages:(NSArray *)images{
    
    @weakify(self);
    [images enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        @strongify(self);
        
        Photos *photo = (Photos *)obj;
        if (idx <6) {
            UIImageView *icon = self.imageIcons[idx];
            [icon sd_setImageWithURL:[NSURL URLWithString:photo.url]];
            icon.hidden = NO;
        }
    }];
}

#pragma mark - getter methods

- (UIScrollView *)scrollView{
    
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] init];
    }
    return _scrollView;
}




@end
